package utils

import (
	"encoding/json"
	"strings"
)

func JSONString(o any) string {
	x, err := json.Marshal(o)
	if err != nil {
		return err.Error()
	}
	return string(x)
}

func SplitString(s string, sep ...string) []string {
	// Default separator is newline
	separators := "\n"

	// If separators are provided, use the first one
	if len(sep) > 0 {
		separators = sep[0]
	}

	// Create a split function that splits on any rune in separators
	splitFunc := func(r rune) bool {
		return strings.ContainsRune(separators, r)
	}

	return strings.FieldsFunc(s, splitFunc)
}
